/**
 * 
 */
package ac.svn.accesscontrol.ui.window;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import ac.svn.accesscontrol.store.IResources;
import ac.svn.accesscontrol.ui.JMenu;
import ac.svn.accesscontrol.ui.XTextPane;
import ac.svn.accesscontrol.utils.UIUtility;
import ac.svn.accesscontrol.utils.Utility;

/**
 * @author Enigmanic
 *
 */
public class GroupEditorWindow extends JFrame 
{
	public GroupEditorWindow() 
	{
		super();
		setTitle("Group Editor");
		setCenteredLocation();
		getContentPane().setLayout(new BorderLayout(0, 0));

		Color WHITE = Color.WHITE;
		Border border = UIUtility.setAllShadowedBorder(null);

		getContentPane().setBackground(WHITE);

		JPanel basePanel = new JPanel();

		basePanel.setBackground(WHITE);
		basePanel.setBorder(border);

		getContentPane().add(basePanel, BorderLayout.CENTER);
		basePanel.setLayout(new BorderLayout(0, 0));

		JPanel titlePanel = new JPanel();
		titlePanel.setBackground(WHITE);
		titlePanel.setBorder(border);
		titlePanel.setLayout(new BorderLayout(0, 0));

		basePanel.add(titlePanel, BorderLayout.NORTH);

		JSplitPane splitPane = new JSplitPane();
		splitPane.setBackground(WHITE);
		splitPane.setBorder(new TitledBorder(border,"Groups"));
		splitPane.setDividerLocation(250);

		basePanel.add(splitPane, BorderLayout.CENTER);

		JScrollPane groupsScrollPane = new JScrollPane();
		groupsScrollPane.setBackground(WHITE);
		groupsScrollPane.setBorder(new TitledBorder((border),"Available groups"));
		splitPane.setLeftComponent(groupsScrollPane);

		groupList = new JList();
		groupList.setBorder(border);

		groupsScrollPane.setViewportView(groupList);

		lblAvailableGroups = new JLabel(" Available Groups");
		lblAvailableGroups.setBorder(border);
		lblAvailableGroups.setFont(new Font("Tahoma", Font.BOLD, 13));
		groupsScrollPane.setColumnHeaderView(lblAvailableGroups);

		JScrollPane editorScrollPane = new JScrollPane();
		editorScrollPane.setBackground(WHITE);
		editorScrollPane.setBorder(new TitledBorder(border,"Group Details"));
		splitPane.setRightComponent(editorScrollPane);

		infoTextPane = new XTextPane();
		editorScrollPane.setViewportView(infoTextPane);

		titleLabel = new JLabel("<HTML>\r\n<p align=\"CENTER\">\r\nWelcome to Group Editor, Create, Edit and Delete SVN groups using this utility.\r\n<br>Help is available in tooltip and Help Menus.\r\n<br>HAPPY EDITING!\r\n</p>\r\n</HTML>");
		titleLabel.setBorder(border);
		editorScrollPane.setColumnHeaderView(titleLabel);
		titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(WHITE);
		buttonPanel.setBorder(border);

		basePanel.add(buttonPanel, BorderLayout.SOUTH);
		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		finishBtn = new JButton("Finish");
		buttonPanel.add(finishBtn);

		toolBar = new JToolBar(JToolBar.VERTICAL);
		toolBar.setBackground(WHITE);
		toolBar.setFloatable(false);
		toolBar.setBorder(border);
		basePanel.add(toolBar, BorderLayout.WEST);

		newGroupBtn = new JButton(Utility.getImageIcon(IResources.LOC_ICN_ADD_GROUPS));
		//newGroupBtn.setIcon(new CompoundIcon(Axis.Y_AXIS, 2,(Utility.getImageIcon(IResources.LOC_ICN_ADD_GROUPS)), (new TextIcon(newGroupBtn,"Add"))));
		newGroupBtn.setBackground(WHITE);
		newGroupBtn.setToolTipText("Add Groups");
		newGroupBtn.setMnemonic('A');
		toolBar.add(newGroupBtn);

		editBtn = new JButton(Utility.getImageIcon(IResources.LOC_ICN_EDIT_GROUPS));
		//editBtn.setIcon(new CompoundIcon(Axis.Y_AXIS, 2,(Utility.getImageIcon(IResources.LOC_ICN_EDIT_GROUPS)), (new TextIcon(editBtn,"Edit"))));
		editBtn.setBackground(WHITE);
		editBtn.setToolTipText("Edit Groups");
		toolBar.add(editBtn);

		deleteBtn = new JButton(Utility.getImageIcon(IResources.LOC_ICN_DELETE_GROUPS));
		//deleteBtn.setIcon(new CompoundIcon(Axis.Y_AXIS,2,(Utility.getImageIcon(IResources.LOC_ICN_DELETE_GROUPS)), (new TextIcon(deleteBtn,"Delete"))));
		deleteBtn.setBackground(WHITE);
		deleteBtn.setToolTipText("Delete Group");
		toolBar.add(deleteBtn);

		JMenuBar menuBar = new JMenuBar();
		menuBar.setBackground(WHITE);
		menuBar.setBorder(border);
		setJMenuBar(menuBar);

		JMenu mnActions = new JMenu("Actions");
		menuBar.add(mnActions);

		createNewGroupMI = new JMenuItem("Create new Group..");
		createNewGroupMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
		mnActions.add(createNewGroupMI);

		deleteSelectedGroupMI = new JMenuItem("Delete selected Group..");
		deleteSelectedGroupMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
		mnActions.add(deleteSelectedGroupMI);

		editSelectedGroupMI = new JMenuItem("Edit selected Group..");
		editSelectedGroupMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK));
		mnActions.add(editSelectedGroupMI);

		closeMI = new JMenuItem("Close");
		closeMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK));
		mnActions.add(closeMI);

		JMenu mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);

		helpTopicsMI = new JMenuItem("Help Topics");
		helpTopicsMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_MASK));
		mnHelp.add(helpTopicsMI);

		setExtendedState(JFrame.MAXIMIZED_BOTH);
	}

	public void setCenteredLocation()
	{
		setSize(800,600);
		Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((int)(size.getWidth()/2 - getWidth()/2),(int)(size.getHeight()/2-getHeight()/2)); 
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton finishBtn;
	private JButton editBtn;
	private JButton deleteBtn;
	private JButton newGroupBtn;
	private JLabel lblAvailableGroups;
	private JList groupList;
	private XTextPane infoTextPane;
	private JMenuItem helpTopicsMI;
	private JMenuItem createNewGroupMI;
	private JMenuItem deleteSelectedGroupMI;
	private JMenuItem editSelectedGroupMI;
	private JMenuItem closeMI;
	private JToolBar toolBar;
	private JLabel titleLabel;
	public JButton getFinishBtn() {
		return finishBtn;
	}
	public JButton getEditBtn() {
		return editBtn;
	}
	public JButton getDeleteBtn() {
		return deleteBtn;
	}
	public JButton getNewGroupBtn() {
		return newGroupBtn;
	}
	public JLabel getLblAvailableGroups() {
		return lblAvailableGroups;
	}
	public JList getGroupList() {
		return groupList;
	}
	public XTextPane getInfoTextPane() {
		return infoTextPane;
	}
	public JMenuItem getHelpTopicsMI() {
		return helpTopicsMI;
	}
	public JMenuItem getCreateNewGroupMI() {
		return createNewGroupMI;
	}
	public JMenuItem getDeleteSelectedGroupMI() {
		return deleteSelectedGroupMI;
	}
	public JMenuItem getEditSelectedGroupMI() {
		return editSelectedGroupMI;
	}
	public JMenuItem getCloseMI() {
		return closeMI;
	}

	/**
	 * @return the titleLabel
	 */
	 public JLabel getTitleLabel() {
		 return titleLabel;
	 }

	 /**
	  * @param titleLabel the titleLabel to set
	  */
	 public void setTitleLabel(JLabel titleLabel) {
		 this.titleLabel = titleLabel;
	 }





}
